package com.witdata.common.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class Result<T> {
    private Integer code;
    private String msg;
    private T data;

    public static <T> Result<T> ok(){
        return new Result<>(200, "", null);
    }

    public static <T> Result<T> ok(String msg){
        return new Result<>(200, msg, null);
    }

    public static <T> Result<T> ok(Status status){
        return new Result<>(status.getCode(),status.getMsg(), null);
    }

    public static <T> Result<T> ok(Status status, T data){
        return new Result<>(status.getCode(),status.getMsg(), data);
    }

    public static <T> Result<T> ok(String msg, T data){
        return new Result<T>(200, msg, data);
    }

    public static <T> Result<T> fail(String msg){
        return new Result<T>(401, msg, null);
    }

    public static <T> Result<T> fail(Integer code, String msg){
        return new Result<T>(code, msg, null);
    }

    public static <T> Result<T> fail(Status status){
        return new Result<T>(status.getCode(), status.getMsg(), null);
    }

}
